<template>
	<view class="content">
		<u-form ref="addform" :model="model" :rules="rules" :errorType="errorType">
			<view class="formBox">
				<view class="title">基础信息</view>
				<u-form-item :label-position="labelPosition" label-width="150" label="展示区域" prop="showArea" required>
					<u-radio-group v-model="showAreaName" :width="radioCheckWidth" :wrap="radioCheckWrap">
						<u-radio shape="circle" v-for="(item, index) in showAreaList"
							@change="radioChange(item.name, 'showArea', item.value)" :key="index" :name="item.name">
							{{ item.name }}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label-width="150" label="商品类型" prop="goodsType"
					v-if="model.showArea == 1" :required="model.showArea == 1">
					<u-radio-group v-model="goodsTypeName" :width="radioCheckWidth" :wrap="radioCheckWrap">
						<u-radio shape="circle" v-for="(item, index) in goodsTypeList" :key="index"
							@change="radioChange(item.name, 'goodsType', item.value)" :name="item.name">
							{{ item.name }}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label-width="150" label="服务类型" prop="serverType"
					v-if="model.showArea == 2" :required="model.showArea == 2">
					<u-radio-group v-model="serverTypeName" :width="radioCheckWidth" :wrap="radioCheckWrap">
						<u-radio shape="circle" v-for="(item, index) in serverTypeList" :key="index"
							@change="radioChange(item.name, 'serverType', item.value)" :name="item.name">
							{{ item.name }}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="serverLabelList.length != 0 && model.showArea == 2" :label-position="labelPosition"
					label="服务标签" prop="serverLabel" label-width="150" :required="model.showArea == 2">
					<u-input v-model="model.serverLabel" :select-open="selectShow" input-align="right"
						placeholder="请选择服务标签" type="select" @click="selectShow = true"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label-width="150" label="商品名称" prop="goodsServerName"
					required>
					<u-input v-model="model.goodsServerName" input-align="right" placeholder="请输入商品名称" type="text">
					</u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label="上传图片" prop="goodsUrl" label-width="200" required>
					<u-upload width="160" :auto-upload="true" :action="action" :file-list="fileList" name="files"
						@on-success="onSuccess" @on-list-change="onListChange" :max-count="model.showArea == 2 ? 1 : 6"
						:show-progress="false" :upload-text="model.showArea == 2 ? '上传图片(最多上传1张)' : '上传图片(最多上传6张)'"
						height="160"></u-upload>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label-width="150" label="套餐介绍" prop="explain"
					v-if="model.showArea == 2" :required="model.showArea == 2">
					<u-input v-model="model.explain" input-align="right" placeholder="请输入介绍" type="text"></u-input>
				</u-form-item>
				<u-form-item v-if="model.showArea == 2" :label-position="labelPosition" label="购买须知" label-width="150"
					prop="notice">
					<u-input v-model="model.notice" input-align="right" placeholder="请输入介绍" type="text"></u-input>
				</u-form-item>
			</view>
			<view v-if="model.showArea == 1 && model.goodsType != 59" class="formBox">
				<view class="title">商品/服务项目</view>
				<view class="f-c-sb" style="line-height: 100rpx;">
					<view class="value">
						<span style="    color: #fa3534;">*</span>
						商品/服务项目
					</view>
					<view class="f-c-fs" style="color: #2979ff;" @click="addShop(1, 0)">
						<u-icon name="plus-circle-fill" color="#2979ff" style="margin-right: 8rpx;" size="35"></u-icon>
						新增
					</view>
				</view>
				<view class="list" v-for="(item, index) in shopList" :key="index">
					<view class="f-c-sb name-wrapper">
						<view class="name">{{ item.name }}</view>
						<view class="f-c-fs">
							<u-icon name="edit-pen-fill" style="margin-right: 15rpx;" color="#999999" size="40"
								@click="addShop(2, index)"></u-icon>
							<u-icon name="trash-fill" color="#999999" size="40" @click="deletShop(index)"></u-icon>
						</view>
					</view>
					<view class="info">
						<view class="f-c-fs num">
							<view class="label">
								原价：
								<text class="value">￥{{ item.oldPrice }}</text>
							</view>
							<view class="label">
								数量：
								<text class="value">{{ item.number }}</text>
							</view>
						</view>
						<view>
							<view class="">描述（20字符）</view>
							<view>{{ item.content }}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="formBox">
				<view class="title">购买信息</view>
				<u-form-item v-if="model.showArea == 1" :label-position="labelPosition" label="支付方式" label-width="150"
					prop="buyWay" required>
					<u-radio-group v-model="buyWayName" :width="radioCheckWidth" :wrap="radioCheckWrap">
						<u-radio v-for="(item, index) in buyWayList" :key="index" :name="item.name" shape="circle"
							@change="radioChange(item.name, 'buyWay', item.value)">
							{{ item.name }}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="model.showArea == 2" :label-position="labelPosition" label="支付方式" label-width="150"
					prop="buyWay" required>
					<u-radio-group v-model="buyWayName" :width="radioCheckWidth" :wrap="radioCheckWrap">
						<u-radio v-for="(item, index) in buyWayList1" :key="index" :name="item.name" shape="circle"
							@change="radioChange(item.name, 'buyWay', item.value)">
							{{ item.name }}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label-width="150" label="原价(元)" prop="costPrice" required>
					<u-input v-model="model.costPrice" :disabled="model.showArea == 1 && model.goodsType != 59"
						input-align="right" placeholder="请输入原价" type="digit"></u-input>
				</u-form-item>
				<u-form-item v-if="model.buyWay == 2" :label-position="labelPosition" label="积分" label-width="150"
					prop="nowPrice" required>
					<u-input v-model="model.nowPrice" input-align="right" placeholder="请输入积分" type="digit"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label-width="150" v-else label="现价(元)" prop="nowPrice"
					required>
					<u-input v-model="model.nowPrice" input-align="right" placeholder="请输入现价" type="digit"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label-width="150" label="剩余数量" prop="surplusNumber"
					v-if="false">
					<u-input v-model="model.surplusNumber" input-align="right" placeholder="请输入剩余数量" type="digit">
					</u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label-width="200" label="虚拟购买人数" prop="inventedNumber">
					<u-input v-model="model.inventedNumber" input-align="right" placeholder="请输入虚拟购买人数" type="digit">
					</u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label-width="150" label="库存" prop="stockNumber" required>
					<u-input v-model="model.stockNumber" input-align="right" placeholder="请输入库存" type="digit"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label-width="150" label="支付退款" prop="isRefund" required>
					<u-radio-group v-model="isRefundName" :width="radioCheckWidth" :wrap="radioCheckWrap">
						<u-radio shape="circle" v-for="(item, index) in isRefundList"
							@change="radioChange(item.name, 'isRefund', item.value)" :key="index" :name="item.name">
							{{ item.name }}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="model.showArea == 1" :label-position="labelPosition" label="使用方式" label-width="150"
					prop="useWay" required>
					<u-radio-group v-model="useWayNmae" :width="radioCheckWidth" :wrap="radioCheckWrap">
						<u-radio v-for="(item, index) in useWayList" :key="index" :name="item.name" shape="circle"
							@change="radioChange(item.name, 'useWay', item.value)">
							{{ item.name }}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label="使用门店" label-width="150" prop="useStores" required>
					<u-radio-group v-model="useStoresName" :width="radioCheckWidth" :wrap="radioCheckWrap">
						<u-radio v-for="(item, index) in useStoresList" :key="index" :name="item.name" shape="circle"
							@change="radioChange(item.name, 'useStores', item.value)">
							{{ item.name }}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="useStoresName == '选择门店'" :label-position="labelPosition" label="选择门店"
					label-width="150" prop="useStores" required>
					<view
						v-if="model.useStores.split(',').length && model.useStores.length != 0 && selectStore.length == 0"
						style="width: 100%;" @click="goselectStore">
						已选择{{ model.useStores.split(',').length }}家门店
					</view>
					<view style="width: 100%;" @click="goselectStore" v-else-if="selectStore.length != 0">已选择{{
              selectStore.length
            }}家门店
					</view>
					<view style="width: 100%;" @click="goselectStore" v-else>请选择门店</view>
				</u-form-item>
			</view>
			<view class="formBox">
				<view class="title">商品详情介绍</view>
				<u-form-item :label-position="labelPosition" label="商品详情" label-width="150" prop="details" required>
					<view style="width: 100%;" @click="goShopDetail">
						{{ model.details.length > 0 ? '修改活动内容' : '请输入购买信息' }}</view>
					<!-- <u-input input-align="right"  placeholder="点击查看详情" disabled v-model="model.details" @click="goShopDetail" type="text"></u-input> -->
				</u-form-item>
			</view>
		</u-form>
		<u-select mode="single-column" :list="serverLabelList" value-name="dictId" label-name="value"
			v-model="selectShow" @confirm="selectConfirm"></u-select>
		<view class="lxdBtn" @click="submit">提交</view>
		<u-popup mode="bottom" border-radius="22" safe-area-inset-bottom closeable v-model="show">
			<view class="formBox-wrapper">
				<view class="formBox">
					<u-form :model="shop" ref="uShop">
						<u-form-item label="商品服务名称" label-width="200rpx" prop="name" required>
							<u-input v-model="shop.name" input-align="right" />
						</u-form-item>
						<u-form-item label="销售价" label-width="200rpx" prop="oldPrice" required>
							<u-input v-model="shop.oldPrice" input-align="right" type="digit" />
						</u-form-item>
						<u-form-item label="数量" label-width="200rpx" prop="number" required>
							<u-input v-model="shop.number" input-align="right" type="digit" />
						</u-form-item>
						<u-form-item label="备注" label-position="top" label-width="200rpx" prop="content">
							<u-input v-model="shop.content" input-align="right" maxlength="20" type="textarea " />
						</u-form-item>
					</u-form>
				</view>

				<view class="lxdBtn" @click="save">保存</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		goodsserverDetail,
		goodsserverEdit,
		goodsserverSave,
		serverLabelListFn
	} from '@/api/index.js';
	import {
		mapGetters
	} from 'vuex';

	export default {
		data() {
			return {
				selectShow: false,
				model: {
					showArea: '1',
					goodsType: '60',
					serverType: '1',
					editType: '',
					goodsServerName: '',
					goodsUrl: '',
					buyWay: '1',
					notice: '',
					explain: '',
					costPrice: '',
					nowPrice: '',
					surplusNumber: '',
					inventedNumber: '',
					stockNumber: '',
					isRefund: '1',
					useStores: '',
					details: '',
					serverLabelId: '',
					serverLabel: ''
				},
				rules: {
					goodsType: [{
						validator: (rule, value, callback) => {
							// 调用uView自带的js验证规则，详见：https://www.uviewui.com/js/test.html
							console.log(123);
							if (this.showAreaName === '商城' && this.goodsTypeName === '') {
								callback(new Error('请选择商品类型'));
							} else {
								callback();
							}
						},
						transform(value) {
							return String(value);
						},
						message: '请选择商品类型',
						// 触发器可以同时用blur和change，二者之间用英文逗号隔开
						trigger: ['change', 'blur']
					}],
					goodsServerName: [{
						required: true,
						message: '此为必填字段',
						transform(value) {
							return String(value);
						},
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur']
					}],
					goodsUrl: [{
						required: true,
						message: '请上传图片',
						transform(value) {
							return String(value);
						},
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur']
					}],
					buyWay: [{
						required: true,
						message: '此为必填字段',
						transform(value) {
							return String(value);
						},
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur']
					}],
					notice: [{
						required: true,
						message: '此为必填字段',
						transform(value) {
							return String(value);
						},
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur']
					}],
					explain: [{
						required: true,
						message: '此为必填字段',
						transform(value) {
							return String(value);
						},
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur']
					}],
					costPrice: [{
						// 自定义验证函数，见上说明
						validator: (rule, value, callback) => {
							return this.$u.test.amount(value);
						},
						transform(value) {
							return String(value);
						},
						message: '金额格式不正确',
						// 触发器可以同时用blur和change
						trigger: ['change', 'blur']
					}],
					nowPrice: [{
							required: true,
							message: '此为必填字段',
							transform(value) {
								return String(value);
							},
							// 可以单个或者同时写两个触发验证方式
							trigger: ['change', 'blur']
						},
						{
							// 自定义验证函数，见上说明
							validator: (rule, value, callback) => {
								return this.$u.test.amount(value);
							},
							transform(value) {
								return String(value);
							},
							message: '金额格式不正确',
							// 触发器可以同时用blur和change
							trigger: ['change', 'blur']
						}
					],
					stockNumber: [{
						required: true,
						message: '此为必填字段',
						transform(value) {
							return String(value);
						},
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur']
					}]
				},
				showAreaList: [{
						name: '商城',
						value: 1,
						checked: false
					},
					{
						name: '门店服务',
						value: 2,
						checked: false
					}
				],
				serverLabelList: [],
				isRefundList: [{
						name: '不支持',
						value: 1,
						checked: false
					},
					{
						name: '支持',
						value: 2,
						checked: false
					}
				],

				useWayList: [{
						name: '邮寄',
						value: 1,
						checked: false
					},
					{
						name: '到店核销',
						value: 2,
						checked: false
					},
					{
						name: '自提',
						value: 3,
						checked: false
					}
				],
				buyWayName: '',
				buyWayList: [{
						name: '货币购买',
						value: 1,
						checked: false
					},
					{
						name: '积分兑换',
						value: 2,
						checked: false
					}
				],
				buyWayList1: [{
					name: '货币购买',
					value: 1,
					checked: false
				}],
				useStoresName: '',
				useStoresList: [{
						name: '当前门店',
						value: 1,
						checked: false
					},
					{
						name: '选择门店',
						value: 2,
						checked: false
					}
				],
				goodsTypeList: [{
						name: '套餐',
						value: 60,
						checked: false
					},
					{
						name: '卡券',
						value: 61,
						checked: false
					},
					{
						name: '商品',
						value: 59,
						checked: false
					}
				],
				serverTypeList: [{
						name: '洗车',
						value: 1,
						checked: false
					},
					{
						name: '钣喷',
						value: 2,
						checked: false
					},
					{
						name: '保养',
						value: 3,
						checked: false
					}
				],
				labelPosition: 'left',
				radioCheckWidth: 'auto',
				radioCheckWrap: false,
				errorType: ['message'],
				showAreaName: '',
				serverTypeName: '',
				goodsTypeName: '',
				isRefundName: '',
				useWayNmae: '',
				fileList: [],
				action: 'https://sj.shopec.com.cn/hty-manage-api/upload/files',
				editStatus: 1, //1、新增 2、编辑
				editStatusIndex: 0, //1、新增 2、编辑
				shopList: [],
				shop: {
					name: '',
					oldPrice: '',
					number: '',
					content: ''
				},
				rulesShop: {
					name: [{
						validator: (rule, value, callback) => {
							if (!value.length) {
								return false;
							} else {
								callback();
							}
						},
						message: '请输入',
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur']
					}],
					oldPrice: [{
						validator: (rule, value, callback) => {
							console.log(value);
							if (!String(value).length) {
								return false;
							} else {
								callback();
							}
						},
						message: '请输入',
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur']
					}],
					number: [{
						validator: (rule, value, callback) => {
							console.log(value);
							if (!String(value).length) {
								return false;
							} else {
								callback();
							}
						},
						message: '请输入',
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur']
					}]
				},
				show: false
			};
		},
		filters: {
			showAreaFilters(type) {
				var text = '';
				switch (type) {
					case 1:
						text = '商城';
						break;
					case 2:
						text = '门店服务';
						break;
				}
				console.log(text);
				return text;
			},
			goodsTypeFilters(type) {
				var text = '';
				switch (type) {
					case 60:
						text = '套餐';
						break;
					case 61:
						text = '卡券';
						break;
					case 59:
						text = '商品';
						break;
				}
				console.log(text);
				return text;
			},
			serverTypeFilters(type) {
				var text = '';
				switch (type) {
					case 1:
						text = '洗车';
						break;
					case 2:
						text = '钣喷';
						break;
					case 3:
						text = '保养';
						break;
				}
				console.log(text);
				return text;
			},
			buyWayFilters(type) {
				var text = '';
				switch (type) {
					case 1:
						text = '货币购买';
						break;
					case 2:
						text = '积分兑换';
						break;
				}
				console.log(text);
				return text;
			},
			isRefundFilters(type) {
				var text = '';
				switch (type) {
					case 1:
						text = '不支持';
						break;
					case 2:
						text = '支持';
						break;
				}
				console.log(text);
				return text;
			},
			useWayFilters(type) {
				var text = '';
				switch (type) {
					case 1:
						text = '邮寄';
						break;
					case 2:
						text = '到店核销';
						break;
					case 3:
						text = '自提';
						break;
				}
				console.log(text);
				return text;
			},
			useStoresFilters(type) {
				var text = '';
				console.log(type);
				switch (type) {
					case '1':
						text = '当前门店';
						break;
					default:
						text = '选择门店';
						break;
				}
				console.log(text);
				return text;
			}
		},
		computed: {
			...mapGetters(['userInfo', 'selectStore', 'selectStoreStr'])
		},
		onLoad(option) {
			this.id = JSON.parse(option.param).id;
			this.editType = JSON.parse(option.param).type;
			this.getdetail();
		},
		onReady() {
			this.$refs.addform.setRules(this.rules);
			this.$refs.uShop.setRules(this.rulesShop);
		},
		onShow() {
			this.model.details = this.$get('addHtml') ? this.$get('addHtml') : this.model.details;
		},
		onUnload() {
			console.log("onUnload");
			this.$remove('addHtml');
			this.$remove('selectStoreIds');
		},
		methods: {
			save() {
				this.$refs.uShop.validate(valid => {
					if (valid) {
						console.log('验证通过');
						if (this.editStatus == 1) {
							this.shopList.push(JSON.parse(JSON.stringify(this.shop)));
						} else if (this.editStatus == 2) {
							this.shopList[this.editStatusIndex] = JSON.parse(JSON.stringify(this.shop));
						}
						var num = 0;
						this.shopList.forEach((val, index) => {
							num += val.oldPrice * val.number;
						});
						this.model.costPrice = num;
						this.show = false;
					} else {
						console.log('验证失败');
					}
				});
			},
			addShop(type, index) {
				this.show = true;
				this.editStatus = type;
				this.editStatusIndex = index;
				if (type == 2) {
					this.shop = this.shopList[index];
					this.$forceUpdate();
				} else {
					this.shop = {
						name: '',
						oldPrice: '',
						number: '',
						content: ''
					};
				}
			},
			deletShop(index) {
				this.shopList.splice(index, 1);
				var num = 0;
				this.shopList.forEach((val, index) => {
					num += val.oldPrice * val.number;
				});
				this.model.costPrice = num;
			},
			getdetail() {
				goodsserverDetail({
					gsId: this.id
				}).then(res => {
					for (let key in res.data) {
						if (!res.data[key]) {
							delete res.data[key];
						}
					}
					this.model = res.data;
					var arr = res.data.goodsUrl;
					if (arr.indexOf(',') != -1) {
						arr.split(',').forEach((val, index) => {
							var urlObj = {};
							urlObj = {
								url: this.$imagePath + val,
								urlBack: val,
								error: false, // 上传失败，此值为true
								progress: 100 // 0-100之间的值
							};
							this.fileList.push(urlObj);
						});
					} else {
						var urlObj = {};
						urlObj = {
							url: this.$imagePath + arr,
							urlBack: arr,
							error: false, // 上传失败，此值为true
							progress: 100 // 0-100之间的值
						};
						this.fileList.push(urlObj);
					}

					this.showAreaName = this.$options.filters['showAreaFilters'](res.data.showArea);
					this.useStoresName = this.$options.filters['useStoresFilters'](res.data.useStores.split(',')
						.length);
					this.isRefundName = this.$options.filters['isRefundFilters'](res.data.isRefund);
					this.buyWayName = this.$options.filters['buyWayFilters'](res.data.buyWay);
					this.useWayNmae = this.$options.filters['useWayFilters'](res.data.useWay);
					this.serverTypeName = this.$options.filters['serverTypeFilters'](res.data.serverType);
					this.goodsTypeName = this.$options.filters['goodsTypeFilters'](res.data.goodsType);
					this.shopList = this.model.gsDtos;
					this.getserverLabelList();
				});
			},

			selectConfirm(e) {
				console.log(e);
				this.model.serverLabel = '';
				e.map((val, index) => {
					this.model.serverLabel = val.label;
					this.model.serverLabelId = val.value;
				});
			},
			radioChange(name, type, value) {
				this[type + 'name'] = name;
				this.model[type] = value;
				if (type == 'goodsType' && value != 59) {
					var num = 0;
					this.shopList.forEach((val, index) => {
						num += val.oldPrice * val.number;
					});
					this.model.costPrice = num;
				} else if (type == 'goodsType' && value == 59) {
					this.model.costPrice = 0;
				}
				if (type == 'serverType') {
					this.getserverLabelList();
				}
				if (type == 'showArea') {
					if (value == 2) {
						this.buyWayName = '货币购买'
						this.model.buyWay = '1'
					}
				}
				if (name == '选择门店') {
					this.model.useStores = '';
					this.goselectStore();
				} else if (name == '当前门店') {
					this.model.useStores = this.userInfo.storeBasicId;
				}
			},
			goselectStore() {
				this.$store.commit('setSelectStoreStr', this.model.useStores);
				this.$navigateTo('/pages/selectStore/selectStore', {});
			},
			onListChange(lists, index) {
				this.fileList = lists;
			},
			goShopDetail() {
				this.$put('addHtml', this.model.details);
				this.$navigateTo('../shopDetail/shopDetail', {});
			},
			getserverLabelList() {
				serverLabelListFn({
					serverType: this.model.serverType ? this.model.serverType : 1
				}).then(res => {
					var isCheckStatus = false;
					res.data.forEach((val, index) => {
						if (val.value == this.model.serverLabel && val.dictId == this.model
							.serverLabelId) {
							isCheckStatus = true;
						}
					});
					if (!isCheckStatus) {
						this.model.serverLabel = '';
						this.model.serverLabelId = '';
					}

					this.serverLabelList = res.data;
				});
			},
			onSuccess(data, index, lists, name) {
				console.log(data, index, lists, name);
				var str = '';
				lists.forEach((val, index) => {
					if (index == lists.length - 1) {
						str = str + val.response.data.saveUrl;
					} else {
						str = str + val.response.data.saveUrl + ',';
					}
				});
				this.model.goodsUrl = str;
			},
			stringAs(string) {
				return string.replace(/(\\|\"|\n|\r|\t)/g, '\\$1');
			},
			submit() {
				this.$refs.addform.validate(valid => {
					if (valid) {
						console.log('验证通过');
						var data = {
							buyWay: 0,
							costPrice: 0,
							details: '',
							explain: '',
							goodsServerName: '',
							goodsType: 0,
							goodsUrl: '',
							gsId: '',
							inventedNumber: 0,
							isRefund: 0,
							notice: '',
							nowPrice: 0,
							serverLabel: '',
							serverLabelId: '',
							serverType: 0,
							showArea: 0,
							stockNumber: 0,
							surplusNumber: 0,
							useStores: this.userInfo.storeBasicId,
							useWay: 0
						};
						if (this.useStoresName == '选择门店') {
							// this.model.useStores = '';
							var str = '';
							if (this.selectStore.length != 0) {
								this.selectStore.forEach((val, index) => {
									if (index == this.selectStore.length - 1) {
										str = str + val.storeId;
									} else {
										str = str + val.storeId + ',';
									}
								});
								this.model.useStores = str;
							} else if (this.model.useStores.length == 0) {
								uni.showToast({
									title: '请选择使用门店',
									icon: 'none'
								});
							}
						} else if (this.useStoresName == '当前门店') {
							this.model.useStores = this.userInfo.storeBasicId;
						}
						for (let key in data) {
							data[key] = this.model[key];
						}
						if (data.showArea == 1) {
							delete data.serverType;
							delete data.serverLabel;
							delete data.serverLabelId;
						} else {
							delete data.goodsType;
						}

						data.storeBasicId = this.userInfo.storeBasicId;
						data.details = encodeURI(this.model.details);
						console.log(data);
						if (data.details.length == 0) {
							uni.showToast({
								title: '请填写商品详情',
								icon: 'none'
							});
							return;
						}
						if (data.showArea == 1 && data.goodsType != 59) {
							if (this.shopList.length > 0) {
								data.gsDtos = this.shopList;
							} else {
								uni.showToast({
									title: '请添加商品/服务项目',
									icon: 'none'
								});
								return;
							}
						} else {
							delete data.gsDtos;
						}
						if (this.editType == 1) {
							goodsserverEdit(data).then(res => {
								if (res.code == 1) {
									this.$store.commit('setSelectStore', []);
									uni.navigateBack({
										delta: 1
									});
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									});
								}
							});
						} else {
							delete data.gsId;
							goodsserverSave(data).then(res => {
								if (res.code == 1) {
									this.$store.commit('setSelectStore', []);
									this.$put('goodsserverSave', 'update')
									uni.navigateBack({
										delta: 1
									});
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									});
								}
							});
						}
					} else {
						console.log('验证失败');
					}
				});
			}
		}
	};
</script>

<style lang="less">
	.content {
		width: 100%;
		min-height: 100vh;
		background: #f5f5f5;
		padding: 20rpx 0;
		box-sizing: border-box;
	}

	.formBox-wrapper {
		height: 70vh;
		padding-top: 50rpx;
	}

	.list:nth-last-child(1) {
		border: 0;
	}

	.list {
		border-bottom: 1px solid #ccc;
		width: 100%;
		padding-bottom: 40rpx;

		.name {
			font-size: 28rpx;
			font-weight: 700;
			text-align: left;
			color: #131313;
			line-height: 36px;
		}

		.info {
			line-height: 50rpx;

			.label {
				width: 50%;
				line-height: 80rpx;
			}
		}
	}
</style>
